package com.helen.adapter;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.helen.entity.DonationListEntity;
import com.helen.shopping.R;
import com.helen.utils.ImageLoadUtil;
import com.helen.utils.MyLog;

import java.text.DecimalFormat;
import java.util.List;


/**
 * Created by yang on 2017/11/23.
 */

public class DonationListAdapter extends BaseQuickAdapter<DonationListEntity, BaseViewHolder> {
    DecimalFormat df = new DecimalFormat("0.00");

    public DonationListAdapter(int layoutResId, List<DonationListEntity> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final DonationListEntity item) {
        try {
            ImageView img = (ImageView) helper.getView(R.id.img);
            TextView tvTitle = (TextView) helper.getView(R.id.tv_title);
            TextView tvContent = (TextView) helper.getView(R.id.tv_content);
            TextView tvGoods = (TextView) helper.getView(R.id.tv_goods);
            TextView tvCount = (TextView) helper.getView(R.id.tv_count);
            TextView tvHaveCount = (TextView) helper.getView(R.id.tv_have_count);
            TextView tvComplete = (TextView) helper.getView(R.id.tv_complete);
            ProgressBar pb = (ProgressBar) helper.getView(R.id.myProgressBar);

            tvTitle.setText(item.getTitle());
            tvContent.setText(item.getContent());
            tvGoods.setText(item.getGoodstype());

            int count = Integer.parseInt(new java.text.DecimalFormat("0").format(item.getCount()));
            int haveCount = Integer.parseInt(new java.text.DecimalFormat("0").format(item.getHavecount()));
            tvCount.setText(count + "");
            tvHaveCount.setText(haveCount + "");
            double speed = Double.parseDouble(df.format((double) haveCount / count));
            MyLog.e("yang", "speed==" + speed);
            tvComplete.setText(speed * 100 + "%");
            pb.setProgress(Integer.parseInt(new java.text.DecimalFormat("0").format(speed * 100)));


            if (!TextUtils.isEmpty(item.getImg().get(0).getUrl())) {
                ImageLoadUtil.displayImage(mContext, img, item.getImg().get(0).getUrl(), R.mipmap.app_logo, R.mipmap.app_logo);
            }


        } catch (Exception e) {
            MyLog.e("yang", "爱心捐赠列表异常" + e.toString());
        }


    }


}
